package com.ruoyi.site.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.site.domain.Tracks;
import com.ruoyi.site.service.ITracksService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.site.domain.Moods;
import com.ruoyi.site.service.IMoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 音乐情绪Controller
 * 
 * @author chuckeytang
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/site/moods")
public class MoodsController extends BaseController
{
    @Autowired
    private IMoodsService moodsService;

    @Autowired
    private ITracksService tracksService;
    /**
     * 查询音乐情绪列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Moods moods)
    {
        startPage();
        List<Moods> list = moodsService.selectMoodsList(moods);
        return getDataTable(list);
    }

    /**
     * 导出音乐情绪列表
     */
    @Log(title = "音乐情绪", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Moods moods)
    {
        List<Moods> list = moodsService.selectMoodsList(moods);
        ExcelUtil<Moods> util = new ExcelUtil<Moods>(Moods.class);
        util.exportExcel(response, list, "音乐情绪数据");
    }

    /**
     * 获取音乐情绪详细信息
     */
    @GetMapping(value = "/{moodId}")
    public AjaxResult getInfo(@PathVariable("moodId") Long moodId)
    {
        return success(moodsService.selectMoodsByMoodId(moodId));
    }

    /**
     * 新增音乐情绪
     */
    @PreAuthorize("@ss.hasPermi('site:moods:add')")
    @Log(title = "音乐情绪", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Moods moods)
    {
        return toAjax(moodsService.insertMoods(moods));
    }

    /**
     * 修改音乐情绪
     */
    @PreAuthorize("@ss.hasPermi('site:moods:edit')")
    @Log(title = "音乐情绪", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Moods moods)
    {
        return toAjax(moodsService.updateMoods(moods));
    }

    /**
     * 删除音乐情绪
     */
    @PreAuthorize("@ss.hasPermi('site:moods:remove')")
    @Log(title = "音乐情绪", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moodIds}")
    public AjaxResult remove(@PathVariable Long[] moodIds)
    {
        return toAjax(moodsService.deleteMoodsByMoodIds(moodIds));
    }

    /**
     * 根据情绪ID查询其下的音乐曲目列表
     */
    @GetMapping("/{moodId}/tracks")
    public TableDataInfo getMoodsMusic(@PathVariable("moodId") Long moodId)
    {
        startPage();
        // 调用 Service 层方法，传入情绪ID进行查询
        List<Tracks> list = moodsService.selectTracksByMoodId(moodId);
        return getDataTable(list);
    }
}
